package main

import (
	"github.com/gotd/td/api"
	"os"
	"os/signal"
	"syscall"

	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()
	r.POST("/api/v1/login", api.Login)
	//r.POST("/api/v1/send_code", api.SendCode)
	//r.POST("/api/v1/send_password", api.SendPassword)
	//r.POST("/api/v1/status", api.LoopLoginStatus)
	//r.POST("/api/v1/logout", api.Logout)
	//r.POST("/api/v1/qrlogin", api.Login)
	//r.POST("/api/v1/request", api.Request)
	// kafka.InitKafkaConn()
	// fmt.Println("初始化 kafka 成功")
	safeExit()
	r.Run(":" + "8082")
}

func safeExit() {
	ch := make(chan os.Signal, 2)
	signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
	go func() {
		<-ch
		//core.UserManagerMap.Range(func(key, value any) bool {
		//	if value != nil {
		//		if c := value.(*core.TgUser).GetTdClient(); c != nil {
		//			c.Stop()
		//		}
		//	}
		//	return true
		//})
		os.Exit(1)
	}()
}
